/*
 * Copyright (C) 2004, Velocityme Partnership
 * SystemPropertiesActions.java
 *
 * Created on 08 October 2004, 08:04
 */

package com.velocityme.www.interfaces.nodeactions;

import com.velocityme.interfaces.*;
import com.velocityme.valueobjects.SystemPropertyValue;
import com.velocityme.www.actionforms.MappedObjectsActionForm;
import com.velocityme.www.actionforms.SystemPropertyActionForm;
import java.util.*;
import javax.servlet.http.*;
import org.apache.struts.action.*;
import org.apache.struts.actions.DispatchAction;

/**
 *
 * @author  Robert
 */
public class SystemPropertiesActions extends NodeActions {
    
    /** Creates a new instance of SystemPropertiesActions */
    public SystemPropertiesActions() {
    }
    
    public ActionForward showNode(ActionMapping mapping, 
                                  ActionForm form,
                                  HttpServletRequest request,
                                  HttpServletResponse response) throws Exception {
        HttpSession session = request.getSession();
        KeySession key = (KeySession)session.getAttribute("sessionKey");
        RemoteClientSession cs = RemoteClientSessionUtil.getHome().create();
        session.setAttribute("systemPropertyValues", cs.getAllSystemPropertyValues(key));
        return mapping.findForward("ACTION_DISPLAY");
    }
    
    public ActionForward showEdit(ActionMapping mapping, 
                                  ActionForm form,
                                  HttpServletRequest request,
                                  HttpServletResponse response) throws Exception {
        HttpSession session = request.getSession();
        KeySession key = (KeySession)session.getAttribute("sessionKey");
        RemoteClientSession cs = RemoteClientSessionUtil.getHome().create();
        SystemPropertyActionForm actionForm = (SystemPropertyActionForm)form;
        actionForm.setSystemPropertyValues(cs.getAllSystemPropertyValues(key));
        return mapping.findForward("ACTION_EDIT");
    }
    
    public ActionForward edit(ActionMapping mapping, 
                              ActionForm form,
                              HttpServletRequest request,
                              HttpServletResponse response) throws Exception {
        HttpSession session = request.getSession();
        KeySession key = (KeySession)session.getAttribute("sessionKey");
        RemoteClientSession cs = RemoteClientSessionUtil.getHome().create();
        SystemPropertyActionForm actionForm = (SystemPropertyActionForm)form;
        if (request.getParameter("btnSubmit").equals("OK")) {
            cs.setSystemPropertyValues(key, actionForm.getSystemPropertyValues());
        }
        NodePK nodePK = new NodePK((Integer)session.getAttribute("nodeId"));
        request.setAttribute("nodePK", nodePK);
        return mapping.findForward("ACTION_SUCCESS");
    }
    
}
